package com.base.core.mvc.web;

import java.lang.reflect.Method;

import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;

import com.gitee.magic.core.utils.StackTraceInfo;
import com.gitee.magic.framework.base.constant.Message;
import com.gitee.magic.framework.head.vo.BaseVO;

/**
 * 全局异常处理
 * @author user
 *
 */
@RestControllerAdvice
public class ExceptionWebController extends ExceptionController{

    @Override
    protected Object response(String name, Message msg, HandlerMethod handlerMethod, Throwable e,Boolean isSend) {
    	Method method = handlerMethod.getMethod();
    	if(BaseVO.class.isAssignableFrom(method.getReturnType())) {
    		return super.response(name, msg, handlerMethod,e,isSend);
    	}else {
    		String stackMessage=StackTraceInfo.getStackTrace(e);
    		ModelAndView mav=new ModelAndView();
        	mav.addObject("code",msg.getCode());
        	mav.addObject("message",stackMessage);
        	mav.setViewName("common/error");
        	return mav;
    	}
//    	if(ModelAndView.class.equals(method.getReturnType())) {
//    		String stackMessage=StackTraceInfo.getStackTrace(e);
//    		ModelAndView mav=new ModelAndView();
//        	mav.addObject("code",msg.getCode());
//        	mav.addObject("message",stackMessage);
//        	mav.setViewName("common/error");
//        	return mav;
//    	}else {
//    		return super.response(name, msg, handlerMethod,e,isSend);
//    	}
    }

}
